#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stack>
using namespace std;

void SortStack(stack<int>& s)
{
	if (s.empty()) return;
	stack<int> help;
	while (!s.empty())
	{
		int s_top = s.top();
		s.pop();
		while (!help.empty() && help.top() < s_top)
		{
			s.push(help.top());
			help.pop();
		}
		help.push(s_top);
	}
	while (!help.empty())
	{
		s.push(help.top());
		help.pop();
	}
}

int main()
{
	stack<int> s;
	s.push(3);
	s.push(4);
	s.push(1);
	s.push(4);
	s.push(2);
	s.push(6);
	SortStack(s);
	return 0;
}